package com.combetter.changxing.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.jakewharton.rxbinding2.view.RxView;
import com.combetter.changxing.R;
import com.combetter.changxing.util.ResUtils;

/**
 * 类名  ElectronicPipe
 * 作者  tlfx: Sean.guo
 * 日期  2019/3/4 11:28
 */
public class ScanFacilityDialog2 extends Dialog {
    View mView;
    TextView tv_scan;

    private MyDialogListener myDialogListener;

    public void setOnClick(MyDialogListener myDialogListener) {
        this.myDialogListener = myDialogListener;
    }

    public ScanFacilityDialog2(@NonNull Context context) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_scan_facility, null);

        tv_scan = mView.findViewById(R.id.tv_scan);
        super.setContentView(mView);


        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setCanceledOnTouchOutside(false); // 外部点击取消

        setCustomDialog();
        initVies();
    }


    private void setCustomDialog() {
        int width = ResUtils.getDimens(getContext(), R.dimen.DIMEN_500PX);
        int height = ResUtils.getDimens(getContext(), R.dimen.DIMEN_300PX);
        getWindow().setLayout(width, height);
    }


    private void initVies() {
        RxView.clicks(tv_scan).subscribe(o -> {
            if (myDialogListener != null) {
                myDialogListener.setOnClick();
            }
            dismiss();
        });
    }

   public interface MyDialogListener {
        void setOnClick();
    }
}
